<template>
  <!-- variableManage -->
  <div class="variableManage">
    <div class="con">
      <div class="left-tree">
        <!-- <el-button type="primary" @click="piliangfn">批量编辑</el-button> -->
        <div class="search" style="margin-bottom:10px">
          <el-input placeholder="输入关键字进行过滤" v-model="filterText"></el-input>
        </div>
        <div class="mytree">
          <el-scrollbar style="height:calc(100% - 10px);width: 100%;">
            <el-tree :data="channelAndDeviceTree" :expand-on-click-node="true" default-expand-all :props="defaultProps"
               node-key="mynum"
              :highlight-current='true' ref="lefttree" @node-click="checkItem" :filter-node-method="filterNode">
              <template  #default="{ node }">
                <div class="custom-tree-node">
                   <img src="../../../public/static/image/elTree/2.0.png" v-show="node.data.entityName=='Channel'" />
                  <img src="../../../public/static/image/elTree/2.0.png" v-show="!node.data.entityName" />
                  <img src="../../../public/static/image/elTree/2.1.png" v-show="node.data.entityName=='Device'" />
                  <span style="padding:0px  5px;">{{ node.label }}</span>
                </div>
                <!-- <el-tooltip class="item" effect="dark" content="批量编辑" placement="top">
                   <img src="../../assets/unifyImg/edit.png" alt="" style="margin-right:10px;width:20px;height:20px" v-show="node.data.entityName=='Channel' &&  node.data.next.length != 0" @click.stop="piliangfn(data)">
                </el-tooltip> -->
               
              </template>
            </el-tree>
          </el-scrollbar>
        </div>
      </div>
      <div class="right-table">
        <div class="search-inputss">
          <div class="piliang">
              <span style="font-size:14px">批量编辑：</span>
              <el-input placeholder="请输入变量名称进行模糊匹配" v-model="searchname" style="width:240px"></el-input>
              <el-button type="primary" style="margin-left:12px" @click="searchfn">搜索</el-button>
              <el-button type="primary"  class="last-el-button" @click="piliangfn">批量编辑</el-button>
          </div>
         <div>
           <el-button type="primary"  @click="add_ed2" class="last-el-button">新增变量</el-button>
         </div>
        </div>
        <div class="mytable">
          <el-table id="demo" ref="table"  height="100%" border  stripe :data="tableData" highlight-current-row 
          @selection-change="handleSelectionChange"
            style="width: 100%">
            <el-table-column type="selection" width="55" align="center"> </el-table-column>
            <el-table-column label="序号" width="60" align="center" type='index'></el-table-column>
            <el-table-column prop="formItemAddr" label="点号" width="80" align="center">
              <template  #default="{row}">
                <div v-if="row.editable">
                  <el-input v-model="row.formItemAddr"  @blur="saveCell(row)" />
                </div>
                <div v-else @dblclick="enableEdit(row)">
                  {{ row.formItemAddr }}
                </div>
              </template>
            </el-table-column>
            <el-table-column prop="name" label="变量名称" min-width="230">
              <template #default="{row}">
                <div v-if="row.editabletow">
                  <el-input v-model="row.name"  @blur="saveCelltow(row)" />
                </div>
                <div v-else @dblclick="enableEdittow(row)">
                  {{ row.name }}
                </div>
              </template>
            </el-table-column>
            <el-table-column prop="fromName" label="变量全名" min-width="230"> </el-table-column>
            <el-table-column  label="报警类型" min-width="180"> 
               <template #default="{row}">
                <div>
                   {{policeListfn(row.eventType)}}
                </div>
                
              </template>
            </el-table-column>
            <el-table-column prop="apptype" label="应用类型" min-width="200" v-if="nowquanxuan"> </el-table-column>
            <el-table-column label="数据类型" width="200" align="center" v-if="!nowquanxuan">
              <template #default="{row}">
                <div v-if="row.editablethree" class="myinputsel">
                  <el-select v-model="row.dataType" placeholder="请选择" @blur="saveCellthree(row)">
                    <el-option v-for="item in dataTypeList" :key="item.value" :label="item.label" :value="item.value">
                    </el-option>
                  </el-select>
                </div>
                <div v-else @dblclick="enableEditthree(row)">
                  {{date_format(row.dataType)}}
                </div>
              </template>
            </el-table-column>
            <el-table-column label="操作" width="180" align="center" fixed="right">
              <template #default="{row}">
                <div class="public-flex" @click="piliangEdit=false,editfn(row)">
                  编辑
                </div>
              </template>
            </el-table-column>


          </el-table>
        </div>
      </div>
      <div class="el-loading-mask" v-show="isMask">
             <div class="el-loading-spinner"><svg viewBox="25 25 50 50" class="circular"> <circle cx="50" cy="50" r="20" fill="none" class="path"></circle></svg></div>
      </div>
      <!-- 单个修改 或者批量修改-->
      <el-dialog width="1100px" draggable  :title="piliangEditDra ? '批量修改' :nowEditRow.variableName" :close-on-click-modal='false' v-model="drawer">
                    <div class="leftandrightdialog">
                        <div class="leftdio" style="margin-right:20px;calc(35% - 10px)">
                             <div class="items">
                                <div class="leftname"><span>*</span> 应用类型组：</div>
                                <el-select v-model="typeGroup" filterable placeholder="请选择">
                                  <el-option v-for="item in groupList" :key="item.id" :label="item.name" :value="item.id">
                                  </el-option>
                                </el-select>
                             </div>
                              <div class="items">
                                <div class="leftname"><span>*</span> 应用类型：</div>
                               <el-select v-model="nowEditRow.appType" filterable placeholder="请选择">
                                  <el-option v-for="item in typeValueList" :key="item.id" :label="item.name" :value="item.no">
                                  </el-option>
                                </el-select>
                             </div>
                              <div class="items">
                                    <div class="leftname"><span>*</span> 报警类型：</div>
                                    <el-select v-model="nowEditRow.eventType" filterable placeholder="请选择">
                                      <el-option v-for="item in policeList" :key="item.no" :label="item.name" :value="item.typeName">
                                      </el-option>
                                    </el-select>
                                </div>
                              <div class="items">
                                    <div class="leftname">转换系数：</div>
                                    <el-input v-model="coefficient" style="width:217px" placeholder="请输入转换系数"/>
                                </div>
                                <div class="items">
                                <div class="leftname">偏移量：</div>
                                <el-input v-model="offSet" style="width:217px" placeholder="请输入偏移量"/>
                                </div>
                        </div>
                        <div class="leftdio" style="width: calc(65% - 10px);">
                            <div class="items">
                                    <div class="leftname">越限类型：</div>
                                     <el-select v-model="nowEditRow.overLimit" filterable placeholder="请选择"
                                        @change="overLimitFn">
                                        <el-option v-for="item in limitList" :key="item.no" :label="item.name" :value="item.no">
                                        </el-option>
                                      </el-select>
                            </div>
                            <div class="items" v-if="nowEditRow.limitValues">
                                    <div class="leftname">越限值列表：</div>
                                   <div class="list">
                                      <span v-for="(e,i) in nowEditRow.limitValues" :key="i" style="margin-top:10px">
                                        <span>{{e.limitName}}:</span>
                                        <el-input v-model="e.limitValue"  style="width: 90px;margin-left: 5px;" />
                                        <el-input v-model="e.alias"  style="width: 150px;margin:0 5px;" />
                                        <span>越限等级:</span>
                                        <el-select v-model="e.limitLevel" placeholder="请选择"  style="width: 80px;margin-left: 5px;">
                                          <el-option label="一般" :value="0" />
                                          <el-option label="紧急" :value="1" />
                                          <el-option label="严重" :value="2" />
                                        </el-select>
                                      </span>
                                    </div>
                            </div>
                        </div>
                    </div>
                    <div class="el-loading-mask" v-show="isMask">
                                    <div class="el-loading-spinner">
                                    <svg viewBox="25 25 50 50" class="circular">
                                        <circle cx="50" cy="50" r="20" fill="none" class="path"></circle>
                                    </svg>
                           </div>
                     </div>
                   <template #footer >
                      <div class="dialog-footer">
                            <el-button  @click="drawer = false" >取 消</el-button>
                            <el-button  class="last-el-button" @click="piliangEditDra?saveBatchfn():finish()" type="primary">确 定</el-button>
                      </div>
                    </template>
      </el-dialog>

      <!-- 新增变量 -->
      <el-dialog width="400px" draggable title="新增变量" :close-on-click-modal='false'
        v-model="dialogVisible">
        <div style="display: flex;justify-content: center;margin-top:20px">
          <el-form :model="temp" ref="temp" :rules="rules" label-width="115px" class="demo-temp">
            <el-form-item label="变量名称:" prop="channelName">
              <el-input v-model="temp.channelName" style=""></el-input>
            </el-form-item>
             <el-form-item label="应用类型组:">
              <el-select v-model="typeGroup" filterable placeholder="请选择">
              <el-option v-for="item in groupList" :key="item.id" :label="item.name" :value="item.id">
              </el-option>
            </el-select>
            </el-form-item>
             <el-form-item label="应用类型:">
             <el-select v-model="nowappType" filterable placeholder="请选择">
              <el-option v-for="item in typeValueList" :key="item.id" :label="item.name" :value="item.no">
              </el-option>
            </el-select>
            </el-form-item>
          </el-form>
        </div>
         <template #footer>
                  <div class="dialog-footer">
                    <el-button @click="dialogVisible = false">取 消</el-button>
                    <el-button type="primary" @click="add_fn('temp')">确 定</el-button>
                  </div>
         </template>
      </el-dialog>

      
    </div>
    <div class="el-loading-mask" v-show="logingindex">
          <div class="el-loading-spinner">
                                      <svg viewBox="25 25 50 50" class="circular">
                                          <circle cx="50" cy="50" r="20" fill="none" class="path"></circle>
                                      </svg>
          </div>
                                   
    </div>
    <div class="el-loading-mask" v-show="logingindex2">
                                    <div class="el-loading-spinner">
                                      <svg viewBox="25 25 50 50" class="circular">
                                          <circle cx="50" cy="50" r="20" fill="none" class="path"></circle>
                                      </svg>
                                      <div>{{myindex}} / {{apiDeviceArr.length}}</div>
                                   </div>
                                   
    </div>
  </div>
</template>

<script>
  import {newgetVariableList,updateAddrOrDataType,findAppTypeAndLimit,findByAppTypeNo,addVariable,updateAppTypeAndLimits} from "../../api/capacity";
  import {getAllTypeByGroup,getAppTypeByGroupId,getChannelAndDeviceTreeapi,getVariableNamesAllByDimName,updateAppTypeAlls} from "../../api/energySubType";
  import request from "../../api/htttp2.js";
  export default {
    data () {
      return {
        nowTableobj:[],
        searchname:"",
        dialogVisible:false,
        temp:{'channelName':""},
        rules: {
          channelName: [
            {required: true,message: '请输入变量名称',trigger: 'blur'}
          ],
        
        },
        deviceNo: '',
        isMask:false,
       
        channelAndDeviceTree: [],
        defaultProps: {
          children: 'next',
          label: 'name'
        },
        filterText: "",
        loading: false,
        tableData: [],
        drawerSize: "700px",
        drawer: false,
        checked: false,
        dataTypeList: [
          {
            value: "0",
            label: "SByte",
          },
          {
            value: "1",
            label: "Int16",
          },
          {
            value: "2",
            label: "Int32",
          },
          {
            value: "3",
            label: "Byte",
          },
          {
            value: "4",
            label: "UInt16",
          },
          {
            value: "5",
            label: "Uint32",
          },
          {
            value: "6",
            label: "Single",
          },
          {
            value: "7",
            label: "Boolean",
          },
        ],
        editRow: {},
        typeGroup: "",//应用类型组
        groupList: [],//应用类型组
        typeValue: "",//应用类型
        typeValueList: [],//应用类型
        limitList: [],//越限类型
        limitVal: "",//越限类型
        policeList: "",//报警类型
        policeVal: "",//报警类型
        nowappType:"",
        nowEditRow: {},
        nowdevice:{},
        coefficient:"",
        offSet:"",
        leftArr:[],
        leftDeviceArr:[],
        apiDeviceArr:[],
        logingindex:false,
        piliangEdit:false,
        nowPiliangObj:{},
        myindex:0,
        logingindex2:false,
        editNameArr:[],
        piliangEditDra:false,
        piliangName:"",
        nowChanelArr:[],
        limitValuesArr:{
           "-1":[],
           "1":[
              {
                  "no": 1,
                  "limitName": "一级越上限",
                  "limitValue": 0,
                  "alias": "一级越上限",
                  "limitType": 1,
                  "limitLevel": null
              },
              {
                  "no": 2,
                  "limitName": "二级越上限",
                  "limitValue": 0,
                  "alias": "二级越上限",
                  "limitType": 1,
                  "limitLevel": null
              },
              {
                  "no": 3,
                  "limitName": "一级越下限",
                  "limitValue": 0,
                  "alias": "一级越下限",
                  "limitType": 0,
                  "limitLevel": null
              },
              {
                  "no": 4,
                  "limitName": "二级越下限",
                  "limitValue": 0,
                  "alias": "二级越下限",
                  "limitType": 0,
                  "limitLevel": null
              }
           ],
           "2":[
                {
                    "no": 5,
                    "limitName": "信号产生",
                    "limitValue": 1,
                    "alias": "信号产生",
                    "limitType": 2,
                    "limitLevel": null
                },
                {
                    "no": 6,
                    "limitName": "信号消失",
                    "limitValue": 0,
                    "alias": "信号消失",
                    "limitType": 2,
                    "limitLevel": null
                }
           ],
           "3":[
              {
                  "no": 7,
                  "limitName": "合位",
                  "limitValue": 1,
                  "alias": "合位",
                  "limitType": 2,
                  "limitLevel": null
              },
              {
                  "no": 8,
                  "limitName": "分位",
                  "limitValue": 0,
                  "alias": "分位",
                  "limitType": 2,
                  "limitLevel": null
              }
            ],
            "4":[
                {
                    "no": 9,
                    "limitName": "已储能",
                    "limitValue": 1,
                    "alias": "已储能",
                    "limitType": 2,
                    "limitLevel": null
                },
                {
                    "no": 10,
                    "limitName": "未储能",
                    "limitValue": 0,
                    "alias": "未储能",
                    "limitType": 2,
                    "limitLevel": null
                }
            ],
            "5":[
                {
                    "no": 11,
                    "limitName": "工作位置",
                    "limitValue": 1,
                    "alias": "工作位置",
                    "limitType": 2,
                    "limitLevel": null
                },
                {
                    "no": 12,
                    "limitName": "实验位置",
                    "limitValue": 0,
                    "alias": "实验位置",
                    "limitType": 2,
                    "limitLevel": null
                }
            ],
            "6":[
                {
                    "no": 13,
                    "limitName": "合闸",
                    "limitValue": 1,
                    "alias": "合闸",
                    "limitType": 2,
                    "limitLevel": null
                },
                {
                    "no": 14,
                    "limitName": "分闸",
                    "limitValue": 0,
                    "alias": "分闸",
                    "limitType": 2,
                    "limitLevel": null
                }
            ],
            "7":[
                {
                    "no": 45,
                    "limitName": "远方",
                    "limitValue": 1,
                    "alias": "远方",
                    "limitType": 0,
                    "limitLevel": null
                },
                {
                    "no": 46,
                    "limitName": "就地",
                    "limitValue": 0,
                    "alias": "就地",
                    "limitType": 0,
                    "limitLevel": null
                }
            ],
            "8":[
                {
                    "no": 17,
                    "limitName": "中断",
                    "limitValue": 1,
                    "alias": "中断",
                    "limitType": 2,
                    "limitLevel": null
                },
                {
                    "no": 18,
                    "limitName": "连通",
                    "limitValue": 0,
                    "alias": "连通",
                    "limitType": 2,
                    "limitLevel": null
                }
            ]
        },
        nowquanxuan:false

      };
    },

    mounted () {
      //应用类型组
      getAllTypeByGroup().then(res => {
        this.groupList = res.data;
        
      })
      this.yuexiangList()

      request({url: "/eventType/findAll",method: "get"}).then(res => {
        if(res.code==200) {
           this.policeList=res.data;
           this.policeList.unshift({
            "createTime": null,
            "no": -1,
            "name": "无",
            "typeName": '-1',
            "soundType": 0,
            "soundFile": "d:报警声.wav",
            "typeImage": "",
            "typeColor": -1,
            "isUse": 1,
            "isAutoShowImage": 1,
            "telNum": "18689366741,13229775688",
            "isUpSend": 1,
            "isAutoShowCamera": 0,
            "eventLevel": 2,
            "id": "-1",
            "entityName": "EventType",
            "soundTypeDesc": "无声音报警"
           });
           this.getChannelAndDeviceTree()
        }

      })
      
    },
    watch: {
       filterText(val) {
        this.$refs.lefttree.filter(val);
      },
      searchname(val){
         if(val === ""){
          this.nowquanxuan = false
            this.getList()
         }
      },
      'typeGroup': function(val) {
        if(val == '' || !val) {
          this.typeOptions = []
          return
        }
        getAppTypeByGroupId({'groupId': val}).then(res => {
          // console.log("获取应用类型",res);
          if(res.code==200) {
            this.typeValueList = res.data
          }
        })
      },
    },

    methods: {
      policeListfn(val){
         if(val === "" || val === null){
           return ""
         }
         var arr1 = this.policeList.filter(item => item.typeName == val)
         if(arr1.length != 0){
           return arr1[0].name
         }
      },
      //获取越限列表
      yuexiangList(){
        request({url: `/limit/findAllGroup`,method: "get"}).then(ress => {
                      this.isMask = false
                      if(ress.code==200) {
                        this.limitList = ress.data;
                       
                        this.limitList.unshift({
                          'createTime':null,
                          'entityName':"LimitGroup",
                          'id':'无',
                          'name':'无',
                          'no':'-1',
                          'type':1
                        });
                      }else {
                         this.isMask = false
                      }
                    })
      },
      // 模糊搜索
      searchfn(){
            // this.logingindex = true
            if(this.searchname === ""){
              this.$message({showClose: true,message: '请输入变量名称',type: 'warning'});
              return
            }
            var dd = new FormData()
            dd.append('dimName',this.searchname)
            this.nowquanxuan = true
            // this.tableData = []
            getVariableNamesAllByDimName(dd).then(res => {
                // this.logingindex = false
                if(res.code == 200){
                  var RESDATA = res.data
                  RESDATA.forEach(item => {
                    item.fromName = item.vname
                    item.name = item.fromNme
                    item.mydeviceNo = item.deviceNo
                  })
                  this.tableData = RESDATA
                  // console.log("数据",RESDATA);
                  // this.editNameArr = RESDATA
                  // this.piliangName = []
                }
            })
      },
      //批量选择
      handleSelectionChange(row){
        this.nowTableobj = row
      },
      //批量编辑
      piliangfn(){
        if(this.nowTableobj.length === 0){
          this.$message({showClose: true,message: '请选择变量',type: 'warning'});
          return
        }
        this.nowEditRow.appType = ""
        this.nowEditRow.eventType = "-1"
        this.coefficient = ""
        this.offSet = ""
        this.nowEditRow.limitValues = []
        this.nowEditRow.overLimit = "-1"
        this.drawer = true
        this.piliangEditDra = true
        
      },
      //确定批量编辑
      saveBatchfn(){
        var variableName = []
        this.nowTableobj.forEach(item => {
           variableName.push({
             variableName:item.fromName,
             deviceNo:item.mydeviceNo
           })
        })
        var params = {
            list:variableName,
            dto:{
              coefficient:this.coefficient,
              offSet:this.offSet,
              eventType:this.nowEditRow.eventType,
              appType:this.nowEditRow.appType,
              overLimit:this.nowEditRow.overLimit,
              limitValues:this.nowEditRow.limitValues
            }
        }
        // console.log("参数",params);
        updateAppTypeAndLimits(params).then(res => {
           if(res.code == 200){
            this.drawer = false
            this.piliangEditDra = false
              this.$message({ type: 'success', message: '修改成功!'});
              this.searchfn()
           }else {
             res.message ? this.$message.error(res.message) :  this.$message.error('修改失败');
           }
        })

        
      },
      // 转换时间戳
      date_format(value) { //value就是插值的数据
        if(!value) {
          return ""
        }
        var arr=['SByte','Int16','Int32','Byte','UInt16','Uint32','Single','Boolean','String','Byte[]','Double','Decimal','Int64','UInt64','SByte']

        return arr[value]
      },
       filterNode(value, data) {
        if (!value) return true;
        return data.name.indexOf(value) !== -1;
      },
      //新增变量
      add_ed2(){
        this.typeGroup = ""
        this.nowappType = ""
        this.temp.channelName = ""
         this.dialogVisible = true
      },
      // 确认添加变量
      add_fn (formName) {
        if(JSON.stringify(this.nowdevice) === '{}'){
            this.$message({showClose: true,message: '请选择设备',type: 'warning'});
           return
        }
        this.$refs[formName].validate(valid => {
          if(valid) {
            
            var params=this.temp;
            var d = {
                'appType':this.nowappType,
                'deviceName':this.nowdevice.name,
                'deviceNo':this.nowdevice.no,
                'variableName':params.channelName,
            }
            this.isMask = true
            addVariable(d).then(res => {
               this.isMask = false
              if(res.code==200) {
                 this.getList()
                 this.getChannelAndDeviceTree()
                this.dialogVisible=false;
                this.$message({showClose: true,message: '添加成功',type: 'success'});

              } else {
                res.message ? this.$message.error(res.message) : this.$message.error('添加失败') 
              }
            })
          
         



          } else {
            return false;
          }
        });
      },
      overLimitFn (v) {
        if(this.piliangEditDra){
          this.nowEditRow.overLimit = v
          this.nowEditRow.limitValues = this.limitValuesArr[v]
          return
        }
        if(v == "-1"){
          this.nowEditRow.limitValues = []
          return
        }
       
        findAppTypeAndLimit({'variableName': this.nowEditRow.variableName,'groupNo': v}).then(res => {
          if(res.code==200) {
            // this.nowEditRow = res.data;
            this.nowEditRow.limitValues = res.data.limitValues
            this.nowEditRow.overLimit = v
            // this.coefficient = res.data.coefficient
            // this.offSet = res.data.offSet
          }
        })
      },
      //确定修改变量
      finish () {
      
          var data = this.nowEditRow;
          data.deviceNo = this.deviceNo;
          data.coefficient = this.coefficient == "" ? 0 : this.coefficient;
          data.offSet = this.offSet == "" ? 0 : this.offSet;
          this.isMask = true
          request({url: "/variable/updateAppTypeAndLimit",method: "post",data}).then(res => {
            this.isMask = false
            if(res.code==200) {
              this.$message({
                type: 'success',
                message: '修改成功!'
              });
              this.drawer = false
              this.nowEditRow = {}
            }else {
                res.message ? this.$message.error(res.message) :  this.$message.error('修改失败');
            }
          })
        
        
      },
      //点号双击
      enableEdit (row) {
        row.editable=true;
        this.$nextTick(() => {
          this.$refs.table.setCurrentRow(row);
          this.$refs.table.$el.querySelector('.el-input input').focus();
        });
      },
      //点号失去焦点
      saveCell (row) {
        row.editable=false;
        this.editRow=row
           this.eidt_fn()

      },
      //变量名双击
      enableEdittow (row) {
        row.editabletow=true;
        this.$nextTick(() => {
          this.$refs.table.setCurrentRow(row);
          this.$refs.table.$el.querySelector('.el-input input').focus();
        });
      },
      //变量名失去焦点
      saveCelltow (row) {
        row.editabletow = false;
        this.editRow=row
         this.eidt_fn()
      },
      //双击数据类型
      //变量名双击
      enableEditthree (row) {
        row.editablethree=true;
      },
      //失去焦点
      saveCellthree(row){
         row.editablethree = false;
        this.editRow = row
         this.eidt_fn()
      },
      //确定修改点号变量名数据类型
      eidt_fn () {
        var arrs=this.editRow.fromName.split(".")
        var d={
          dataType: this.editRow.dataType,
          fromItemAddr: this.editRow.formItemAddr,
          newName: arrs[0]+'.'+this.editRow.name,
          oldName: this.editRow.fromName
        }
        this.isMask = true
        updateAddrOrDataType(d).then(res => {
          if(res.code == 200){
               this.$message({ type: 'success', message: '修改成功!' });
               this.getChannelAndDeviceTree()
             this.isMask = false
          }else {
              this.getList()
              res.message ? this.$message.error(res.message) :  this.$message.error('添加失败');
          }
        })
      },
      getChannelAndDeviceTree () {
        this.isMask = true
        getChannelAndDeviceTreeapi().then(res => {
          this.isMask = false
           if(res.success){
             this.channelAndDeviceTree = [res.data]
             var mynum = 1
             this.channelAndDeviceTree.forEach(item => {
                 item.mynum  = mynum++
                 item.next.forEach(tt => {
                     tt.mynum  = mynum++
                     tt.next.forEach(ttt => {
                         ttt.mynum  = mynum++
                     })
                 })
             })
             if(this.channelAndDeviceTree.length != 0 && this.channelAndDeviceTree[0].next.length != 0){
                if(this.channelAndDeviceTree[0].next[0].next.length != 0){
                    this.$nextTick(() => {
                       this.$refs.lefttree.setCurrentKey(this.channelAndDeviceTree[0].next[0].next[0].mynum)
                       this.checkItem(this.channelAndDeviceTree[0].next[0].next[0])

                    })
                }
             }
           }
        })
      },
      
    
    

      checkItem (val) {
        if(val.entityName == 'Device'){
            // console.log("val",val);
            this.deviceNo=val.no;
            this.nowdevice = val
            this.tableData=[]
            this.getList()
        }
      },
      getList () {
        this.isMask = true
        newgetVariableList({'deviceNo': this.deviceNo}).then(res => {
          if(res.code==200) {
            res.data.forEach(item => {
              item.editable=false
              item.editabletow=false
              item.editablethree=false
              item.mydeviceNo = this.deviceNo
            })
            this.tableData=res.data
          }
          this.isMask = false
        })
      },
      //确定修改
      editfn (row) {
        this.piliangEditDra = false
        this.isMask = true
        this.drawer = true
        
        findAppTypeAndLimit({'variableName': row.fromName}).then(res => {
          if(res.code==200) {
             this.coefficient = res.data.coefficient
            this.offSet = res.data.offSet
            this.nowEditRow = res.data;
            // console.log("this.nowEditRow",this.nowEditRow);
             if(this.nowEditRow.overLimit == -1) {
              this.nowEditRow.overLimit= "-1"
            }
             if(this.nowEditRow.eventType == "") {
              this.nowEditRow.eventType= null
            }
            findByAppTypeNo({'no':this.nowEditRow.appType}).then(typeRes => {
              this.isMask = false
                 if(typeRes.code == 200){
                    this.typeGroup = typeRes.data.id
                 }
            })
            
          }else {
             this.isMask = false
          }
        })

    },


    },
    
  };
</script>

<style lang="scss" scoped>
 .variableManage {
   position: relative;
 }
 .leftandrightdialog .leftname {
    min-width: 90px !important;
 }
 .piliang {
   display: flex;
   align-items: center;
   span {
     white-space: nowrap;
   }
 }
  .list {
    display: flex;
    flex-direction: column;
  }

  .con {
    width: 100%;
    height: 100%;
    display: flex;
   position: relative;
    .drawer-con {
      padding: 12px 20px 20px 20px;
      position: relative;
    }

    .duanxin {
      margin-top: 30px;
    }

    :deep(.myinputsel .el-input__inner) {
      height: 24px;
      line-height: 24px;
    }

    :deep(.myinputsel .el-input__suffix) {
      display: flex;
      align-content: center;
    }

    :deep(.myinputsel .el-input__icon) {
      line-height: 24px;
    }

    .mydraweritem {
      display: flex;
      margin-top: 20px;
      align-items: center;

      .item-name {
        width: 90px;
        display: flex;
        justify-content: flex-end;
      }
    }

    :deep(.right-table .el-input--mini .el-input__inner) {
      height: 24px;
      line-height: 24px;
    }

    .left-tree {
      width: 300px;
      height: 100%;
      background-color: #fff;
      padding: 12px;
      box-sizing: border-box;

      .mytree {
         width: 100%;
         height: calc(100% - 50px);
      }
      .custom-tree-node {
         flex: 1;
        //  justify-content: space-between;
         div {
          display: flex;
          align-items: center;
         }
      }
    }

    .right-table {
      width: calc(100% - 308px);
      height: 100%;
      background-color: #fff;
      padding: 12px 20px;
      box-sizing: border-box;
      margin-left: 8px;
      .mytable {
        width: 100%;
        height: calc(100% - 70px);
      }
    }
  }
  .search-inputss {
       width: 100%;
       display: flex;
       justify-content: space-between;
       margin: 0px 0px 12px 0px;
    }
</style>